<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/define/dbmeta"/>

<div class="pageContent" >
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="add" onclick="addDbMeta('添加数据库元数据');" title="添加"><span>添加</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="modifyDbMeta();" title="修改" ><span>修改</span></a></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="saveAllDbMeta();" title="保存"><span>保存</span></a></li>
			<li class="line">line</li>
			<li><a class="delete" onclick="deleteDbMeta();"><span>删除</span></a></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="inputDBMeta('导入数据库');" title="导入数据库"><span>导入数据库</span></a></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="ouputDBMeta('导出数据库');" title="导出数据库"><span>导出数据库</span></a></li>

		</ul>
	</div>

	<table class="table" width="100%" layoutH="138">
		<thead>
			<tr>
				<th width="100">名称</th>
				<th width="40">启用</th>
			</tr>

		</thead>
			<tbody>
			<c:if test="${! empty bean}">
			<c:forEach var="vo" items="${bean}">
			<c:set var="data" value="${vo.value}" />
			<tr target="params" rel="${data.name}" class="base_define_dbmeta_list_tr">
				<td>${data.name}</td>
				<td>
					<c:if test="${data.used}">启用</c:if>
				</td>
			</tr>
			</c:forEach>
			</c:if>
		</tbody>
	</table>

</div>

<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alert(json.callbackType);
		if(json.callbackType){
			navTab.reload("${path}/list.html");//刷新
			setTimeout(function(){$.pdialog.closeCurrent();}, 100);
		}
	}
}

function addDbMeta(title){
	var url = "${path}/add.html";
	$.pdialog.open(url, "base_define_dbmeta_add", title,{width:520,height:380,mask:true,maxable:false,resizable:true});
}

function modifyDbMeta(){
	var rel = '';
	$('.base_define_dbmeta_list_tr').each(function(){
		// alert($(this).attr('rel'));
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		var title = "更新数据库元数据";
		var url = "${path}/get.html?name=" + rel;
		$.pdialog.open(url, "base_define_dbmeta_add", title,{width:520,height:380,mask:true,maxable:false,resizable:true});
	}
}


function deleteDbMeta(){
	var rel = '';
	$('.base_define_dbmeta_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var url = "${path}/delete.html?name=" + rel;
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/list.html";
						navTab.reload(url);
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}

function saveAllDbMeta(){
	var url = "${path}/saveAll.html";
	$.ajax({
		type: "post", url: url,
		success: function(json){
			var result = JSON.parse(json); 
			if (result.statusCode == DWZ.statusCode.ok){
				alertMsg.correct(result.message);
			}
		},
		error: function(){
			alertMsg.error('系统错误，请联系管理员！');
		}
	});
}

function inputDBMeta(title){
	var url = "..${ctx}/upload/view.html?js_back_function=inputDBMetaConsultBack";
	//window.open (url, "newwindow", "height=300, width=600, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //写成一行
	$.pdialog.open(url, "base_define_DBMeta_inportxls", title,{width:720,height:380,mask:true,maxable:false,resizable:true});
}

function inputDBMetaConsultBack(){
	var url = "${path}/input.html";
	$.ajax({
		type: "post", url: url,
		success: function(rs){
			alertMsg.correct(rs.message);
		},
		error: function(){
			alertMsg.error('系统错误，请联系管理员！');
		}
	});
}

function ouputDBMeta(title){
	var url = "${path}/output.html";
	window.open (url, "newwindow", "height=300, width=600, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //写成一行
	//$.pdialog.open(url, "base_define_database_outportxls", title,{width:720,height:380,mask:true,maxable:false,resizable:true});
}
</script>

